package com.jk.service;

import com.jk.dao.PayLogMapper;
import com.jk.pojo.PayLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 交易记录业务层
 */
@Service("payLogServiceImplLiyg")
public class PayLogServiceImplLiyg implements PayLogServiceLiyg {
    @Autowired
    private PayLogMapper payLogMapper;

    /**
     * 分页查询交易记录
     */
    public List<PayLog> queryPayLogList(PayLog payLog) {
        System.out.println(payLog);
        return payLogMapper.queryPayLogList(payLog);
    }
    /**
     * 交易记录逻辑删除
     */
    @Override
    public boolean updateDelete(String logId) {
        try {
            payLogMapper.updateDelete(logId);
            return true;
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 分页查询回收站
     */
    public List<PayLog> queryRecycleList(PayLog payLog) {
        return payLogMapper.queryRecycleList(payLog);
    }
    /**
     * 回收站物理批量删除
     */
    @Override
    public boolean deleteRecycleList(String ids) {
        try {
            //根据逗号分割
            String[] idList = ids.split(",");
            //定义一个空的ArrayList用来存分割的数据
            List<String> idsList = new ArrayList<String>();
            //for循环遍历分割的数据
            for (int i = 0; i <idList.length ; i++) {
                //把数据放到ArrayList中
                idsList.add("\""+idList[i]+"\"");
            }
            payLogMapper.deleteRecycleList(idsList);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 回收站数据批量还原
     */
    public boolean updateReduction(String ids) {
        try {
            //根据逗号分割
            String[] idList = ids.split(",");
            //定义一个空的ArrayList用来存分割的数据
            List<String> idsList = new ArrayList<String>();
            //for循环遍历分割的数据
            for (int i = 0; i <idList.length ; i++) {
                //把数据放到ArrayList中
                idsList.add("\""+idList[i]+"\"");
            }
            payLogMapper.updateReduction(idsList);
            return true;
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    //下载账单
    public Map billDownloadingByThread(Integer page, Integer rows) {
        int start = (page-1)*rows;
        int end = rows;

        int total = payLogMapper.queryCount();
        List<PayLog> list = payLogMapper.queryPactList(start,end);
        Map m = new HashMap();
        m.put("rows", list);
        m.put("total", total);
        return m;
    }
}
